package com.iweipan.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.iweipan.R;
import com.iweipan.base.WPBaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by xyb on 2016/12/26.
 */

public class ReceiverWebActivity extends WPBaseActivity {

    @BindView(R.id.iv_section_title_back)
    ImageView ivSectionTitleBack;
    @BindView(R.id.ll_section_title_back)
    LinearLayout llSectionTitleBack;
    @BindView(R.id.tv_section_title_title)
    TextView tvSectionTitleTitle;
    @BindView(R.id.tv_section_title_right)
    TextView tvSectionTitleRight;
    @BindView(R.id.ll_section_title_right)
    LinearLayout llSectionTitleRight;
    @BindView(R.id.rl_section_title)
    RelativeLayout rlSectionTitle;
    @BindView(R.id.progressBar)
    ProgressBar progressBar;
    @BindView(R.id.webview)
    WebView webview;
    private String webUrl = null;

    @Override
    public int bindLayout() {
        return R.layout.activity_receiverweb;
    }

    @Override
    public void initToolbarColor() {

    }

    @Override
    public void initView(View view) {

        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setCacheMode(WebSettings.LOAD_DEFAULT);
        settings.setDomStorageEnabled(true);
        webview.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                progressBar.setProgress(newProgress);

            }

            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                tvSectionTitleTitle.setText(title);
            }
        });
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                progressBar.setVisibility(View.GONE);
            }

        });


    }

    @Override
    public void doBusiness(Context mContext) {
        Intent intent = getIntent();
        webUrl = intent.getStringExtra("webUrl");
        if (webUrl != null) {
            webview.loadUrl(webUrl);
        }
    }

    @Override
    public void resume() {

    }

    @Override
    public void destroy() {

    }


    @OnClick({R.id.iv_section_title_back, R.id.ll_section_title_back, R.id.tv_section_title_title})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_section_title_back:
                if (ReceiverWebActivity.this != null) {
                    finish();
                }
                break;
            case R.id.ll_section_title_back:
                break;
            case R.id.tv_section_title_title:
                break;
        }
    }
}
